#include <iostream>
using std::cout;
using std::endl;

#include <unistd.h>
#include <pthread.h>

int count = 0;

void *fun1(void* args)
{
    while(true)
    {
        cout<<"fun1执行中..."<< "count:"<< count <<endl;
        sleep(1);
        ++count; //线程间共享资源 与进程的写实拷贝不同 所以多线程共享资源需要上锁
    }
}

void *fun2(void* args)
{
    while(true)
    {
        cout<<"fun2执行中..."<< "count:"<< count <<endl;
        sleep(1);
        //int i = 5/0; 一个线程出问题进程直接终止
    }
}

int main()
{
    pthread_t t1,t2;
    pthread_create(&t1,nullptr,fun1,nullptr);
    pthread_create(&t1,nullptr,fun2,nullptr);
    while(true)
    {
        cout<<"主线程执行中..."<< "count:"<< count <<endl;
        sleep(1);
    }
    return 0;
}